package com.gmss.crawler.enums;

import java.util.Arrays;
import java.util.Optional;

public enum CompanyEnum {

    GOVERNMENT_OFFICE(0, "事业单位"),
    SCHOOL(1, "大专院校"),
    COUNTRY_COMPANY(2, "国有企业"),
    FOREIGN_COMPANY(3, "境外单位"),
    OTHER_COMPANY(4, "其他企业");

    /**
     * 编码
     */
    private Integer code;

    private String value;


    CompanyEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }


    /**
     * 根据code获取枚举对象
     *
     * @param code
     * @return
     */
    public static CompanyEnum getEnum(Integer code) {
        if (null == code ) {
            return null;
        }
        CompanyEnum[] values = CompanyEnum.values();
        if (null != values && values.length > 0) {
            Optional<CompanyEnum> first = Arrays.stream(values).filter(enu -> code.equals(enu.getCode())).findFirst();
            if (first.isPresent()) {
                return first.get();
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }
}
